local ls = require("luasnip")
local s = ls.snippet
local t = ls.text_node
local i = ls.insert_node
local fmt = require("luasnip.extras.fmt").fmt
local rep = require("luasnip.extras").rep

ls.add_snippets("vue", {
  -- Vue 3 Template
  s("vue3", fmt([[
  <template>
  
  </template>
  
  <script setup lang="ts">
  {}
  </script>
  
  <style scoped>
  
  </style>]], {i(0)})),

  -- Vue 2 Template
  s("!vue2", t([[
  <template>
  
  </template>
  
  <script>
  export default {
  
  };
  </script>
  
  <style>
  </style>]])),

  -- Teleport
  s("teleport", fmt([[
  <teleport to="">
  {}
  </teleport>]], {i(0)})),

  -- Interpolation
  s("r", fmt("{{ {} }}", {i(0)})),

  -- Slot scope
  s("slot-scope", fmt('slot-scope="{}"', {i(0)})),

  -- Slot
  s("slot", fmt("<slot>{}</slot>", {i(0)})),

  -- Transition
  s("transition", fmt("<transition>{}</transition>", {i(0)})),

  -- Transition group
  s("transition-group", fmt("<transition-group>{}</transition-group>", {i(0)})),

  -- Components
  s("components", fmt([[
  components: {{
    {}
  }}]], {i(0)})),

  -- Emit
  s("$emit", fmt("$emit({})", {i(0)})),

  -- Bus
  s("$bus", t("$bus")),

  -- On
  s("$on", fmt("$on({})", {i(0)})),

  -- Methods
  s("methods", fmt([[
  methods: {{
    {}
  }},]], {i(0)})),

  -- Lifecycle hooks
  s("beforeCreate", fmt([[
  beforeCreate() {{
    {}
  }}]], {i(0)})),

  s("created", fmt([[
  created() {{
    {}
  }}]], {i(0)})),

  s("beforeMount", fmt([[
  beforeMount() {{
    {}
  }}]], {i(0)})),

  s("mounted", fmt([[
  mounted() {{
    {}
  }}]], {i(0)})),

  -- Tag
  s("t", fmt([[
  <{}>
    {}
  </{}>
  {}
  ]], {i(1, "div"), i(2), rep(1), i(0)})),

  -- Inline Tag
  s("ti", fmt([[
  <{} />
  ]], {i(0)})),
})

-- Vue 文件也可以使用 JavaScript/TypeScript 的代码片段
ls.filetype_extend("vue", { "javascript", "typescript" })
